package com.lanxin.oa.zc.controller;

import com.lanxin.bean.*;
import com.lanxin.oa.zc.service.ZcGouMaiService;
import com.lanxin.util.PageBean;
import com.lanxin.util.TimeConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("zcgm")
public class ZcGouMaiController  extends TimeConverter {
    @Autowired
    ZcGouMaiService gmservice;
    @RequestMapping("select")
    public ModelAndView selectzcgm(Integer empid){
        empid=1;
        List<ZcAssetpurchaseapply> list=gmservice.selectzcgm(empid);
        List<ZzEmployee> emplist=gmservice.selectEmpByempName();
        List<LcFlow>lclist=gmservice.selectflow();
        List<ZzDepartment> deptlist=gmservice.selectDeptById();
        ModelAndView mv=new ModelAndView();
        mv.addObject("list",list);
        mv.addObject("emplist",emplist);
        mv.addObject("lclist",lclist);
        mv.addObject("deptlist",deptlist);
        mv.setViewName("../view/zc/zcgoumai.jsp");
        return mv;
    }

    @RequestMapping("insert")
    public ModelAndView insertzcgm(ZcAssetpurchaseapply zcAssetpurchaseapply, String[] assetName, String[] assetNumber, String[] guige, Integer[] shengou, Double[] unitPrice, Integer[] quantity){
        gmservice.insert(zcAssetpurchaseapply,assetName,assetNumber,guige,shengou,unitPrice,quantity);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }

    @RequestMapping("tijiao")
    public ModelAndView tijiaozcgm(Integer oid,String status){
        gmservice.tijiao(status,oid);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }

    @RequestMapping("toupdate")
    public ModelAndView toupdatezcgm( Integer oid){
        ZcAssetpurchaseapply gm= gmservice.selectByid(oid);
        List<ZzEmployee> emplist=gmservice.selectEmpByempName();
        List<LcFlow>lclist=gmservice.selectflow();
        List<ZzDepartment> deptlist=gmservice.selectDeptById();
        ModelAndView mv=new ModelAndView();
        mv.addObject("gm",gm);
        mv.addObject("emplist",emplist);
        mv.addObject("lclist",lclist);
        mv.addObject("deptlist",deptlist);
        mv.setViewName("../view/zc/zcgmupdate.jsp");
        return mv;
    }


    @RequestMapping("update")
    public ModelAndView updatezcgm(ZcAssetpurchaseapply zcAssetpurchaseapply,Integer mxoid[], String[] assetName, String[] assetNumber, String[] guige, Integer[] shengou, Double[] unitPrice, Integer[] quantity
    ){
        gmservice.update(zcAssetpurchaseapply,mxoid,assetName,assetNumber,guige,shengou,unitPrice,quantity);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }
    @RequestMapping("delete")
    @ResponseBody
    public Boolean deletezcgm(ZcAssetpurchaseapply zcAssetpurchaseapply){
        return gmservice.delete(zcAssetpurchaseapply);
    }

    @RequestMapping("tobaojia")
    public ModelAndView deletezcgm(Integer oid){
        List list= gmservice.selectmx(oid);
        ModelAndView mv=new ModelAndView();
        mv.addObject("list",list);
        mv.setViewName("../view/zc/zcbaojia.jsp");
        return mv;
    }
    @RequestMapping("insertzcbj")
    public ModelAndView insertzcbj( ZcAssetpurchaseapplydetails mx,Double[] price, String[] linkman, String[] linkPhone, String[] remark){
        gmservice.insertbaojia(mx,price,linkman,linkPhone,remark);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("redirect:select");
        return mv;
    }

    @RequestMapping("selectall")
    public ModelAndView selectallzcgm(Integer page,Integer pageSize){
        PageBean<ZcAssetpurchaseapply> list=gmservice.selectallzcgm(page,pageSize);
        List<ZzEmployee> emplist=gmservice.selectEmpByempName();
        List<ZzDepartment> deptlist=gmservice.selectDeptById();
        ModelAndView mv=new ModelAndView();
        mv.addObject("list",list);
        mv.addObject("emplist",emplist);
        mv.addObject("deptlist",deptlist);
        mv.setViewName("../view/zc/zcgoumaiall.jsp");
        return mv;
    }

    @RequestMapping("selectdept")
    @ResponseBody
    public List selectdept(){
        return gmservice.selectDeptById();
    }

    @RequestMapping("selectemp")
    @ResponseBody
    public List selectemp(){
        return gmservice.selectEmpByempName();
    }

    @RequestMapping("selectjob")
    @ResponseBody
    public List selectjob(){
        return gmservice.selectJob();
    }


}
